<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<head>
	<title>WithDrawal Form</title>
	
	<meta charset="utf-8" />
	
	<link rel="stylesheet" href="css/withdrawal.css" type="text/css" media="all" />
	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
	
<script type="text/javascript">
$(document).ready(function() { 

	$("#send").click(function(event) { 
		if($("#fname").val()!='' && $("#emailid").val()!='' && $("#ifsc").val()!='' && $("#accno").val()!='' && $("#bname").val()!='' && $("#amount").val()!='' ){
			
		var reqUrl="./bank/withdrawal";
	var withdrawJson=JSON.stringify({"fname":$("#fname").val(),"emailid":$("#emailid").val(),"ifsc":$("#ifsc").val(),"accno":$("#accno").val(),"bname":$("#bname").val(),"w_mode":$("#w_mode").val(),"amount":$("#amount").val(),"comments":$("#comments").val(),"user_Id":$("#userId").val(),"brokeId":$("#brokerId").val()});
	
	$.ajax(
		  {
		  type: "POST",
		  url: reqUrl,
		  dataType: "json",
		  contentType: 'application/json',
		  data:withdrawJson ,
		  success: function(html) { 			 
		    alert(html);
		  }
		  
		});
	 event.preventDefaults();
		}
	});
});
</script>
<script>

function formvalidation(){
	var email_check = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var alpha_num_check = /^([a-zA-Z0-9\s])+$/;
	var alpha_check = /^([a-zA-Z\.\s])+$/;
	var phone_check= /\(?\d{2}\)?([-\/\.])\d{3}\1\d{4}/;
	var website_check= /^(http|ftp):\/\/(www\.)?.+\.(com|net|org)$/;
	var error	=	false;
		
		
		 if((document.getElementById('emailid').value)==''){
			document.getElementById('umailErrorLable').innerHTML='*Enter  E-mail id.';
			error	=	true;
		}
			if((document.getElementById('fname').value)==''){
			document.getElementById('pnameErrorLable').innerHTML='*Enter First name.';
			error	=	true;
		}
			
			if((document.getElementById('ifsc').value)==''){
				document.getElementById('ifscErrorLable').innerHTML='*Enter IFSC Code.';
				error	=	true;
			}
			if((document.getElementById('accno').value)==''){
				document.getElementById('accnoErrorLable').innerHTML='*Enter Account Number.';
				error	=	true;
			}
			if((document.getElementById('bname').value)==''){
				document.getElementById('bnameErrorLable').innerHTML='*Enter  Bank Name.';
				error	=	true;
			}
			if((document.getElementById('amount').value)==''){
				document.getElementById('amountErrorLable').innerHTML='*Enter Amount.';
				error	=	true;
			}
		
		if(error==false){
			return true;
			}else{ 
			return false;
		}
}

function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
</script>

<script type="text/javascript">
 window.onload=$(document).ready(function() {  	
		$.get('./brokerList',function(responseJson) {
			
			var select = document.getElementById("brokerId");
			 
			var option = document.createElement("option");
			select.appendChild(option);
	            if(responseJson!=null){      	
	                 for(var i=0; i<responseJson.length; i++ ){  
	       
			            			var option = document.createElement("option");
			            			option.value =responseJson[i]['userId'] ;
			            	        option.textContent = responseJson[i]['userId'];
			            	        select.appendChild(option);
						        
					
						  }
	            } 
	      });
   	});
</script>

<script>
    $(document).ready(function() {
        $('#brokerId').change(function(event) {  
        	
        var $brokerId=$("select#brokerId").val();
     
           $.get('./userList',{brokerName:$brokerId},function(responseJson) {   
           
            $('#userId option[value!="0"]').remove();
            
           var select = document.getElementById("userId");
           var option1 = document.createElement("option");
           select.appendChild(option1);
            if(responseJson!=null){      	
                 for(var i=0; i<responseJson.length; i++ ){             			 
		            			var option = document.createElement("option");
		            			option.value =responseJson[i]['user_ID'] ;
		            	        option.textContent = responseJson[i]['user_ID'];
		            		     select.appendChild(option);
					        
				
					  }
            }  
           
           });
        });
    });          
</script> 
</head>
 
<body>
<div><img src="img/ncmx-logo1.png" style="width:150px;height:60px;"></img></div>
	<h2>Withdrawal Form</h2>
    <p>To withdraw funds from your account, please complete and submit the form below.<br>

A withdrawal request will be processed only if you have sufficient available funds. If you traded today, the funds will not be available to withdrawal until the following business day.<br>

Please note: In accordance with anti-money laundering regulations, all withdrawals will be sent from the name on the account.</p>

	
	<form class="form" method="post" id="withdrawal">
		
		<div class="name" id="field1">
        
        	<div class="field2">
			<label for="name" class="label-field">ExchangeID</label>
			<span><sec:authentication property="principal.username"/></span>
            </div>
             <div class="field2">
			<label for="name" class="label-field1">Broker ID</label> 
			<select id="brokerId" name="brokerId"></select>
            </div>
            <div class="field2">
			<label for="name" class="label-field1">Client ID</label> 
			<select id="userId" name="userId"></select>
            </div>
            
		</div>
		<div class="web" id="field1">
        <div class="field2">
			<label for="name" class="label-field">Client Name<b><font color="red" size="3">*</font></b></label> 
			<input type="text" name="fname" id="fname" placeholder="Enter your last name" />
            <div id="pnameErrorLable" style="text-align: right;"></div></div>
        	<div class="field2">
			<label for="name" class="label-field1">Email<b><font color="red" size="3">*</font></b></label> <input type="text" name="emailid" id="emailid" placeholder="mail@example.com" />
            <div id="umailErrorLable" style="text-align: right;"></div>
             </div>
           
		</div>
			<div class="name" id="field1">
		<div class="field2">
			<label for="name" class="label-field">IFSC CODE<b><font color="red" size="3">*</font></b></label> 
			<input type="text" name="ifsc" id="ifsc" placeholder="Enter IFSC Code" onkeypress="return isNumberKey(event)"/>
            <div id="ifscErrorLable" style="text-align: right;"></div></div>
		</div>
		
		
		<div class="web" id="field1">
		
        	<div class="field2">
				<label for="web" class="label-field">Bank Account Number<b><font color="red" size="3">*</font></b></label> 
				<input type="text" name="accno" id="accno" placeholder="Your account number" onkeypress="return isNumberKey(event)" />
			<div id="accnoErrorLable" style="text-align: right;"></div></div>
            
            <div class="field2">
				<label for="email" class="label-field1">Bank Name<b><font color="red" size="3">*</font></b></label>
                	<input type="text" name="bname" id="bname" placeholder="Your Bank Name" />
			<div id="bnameErrorLable" style="text-align: right;"></div></div>
		</div>	
        
        <div class="web" id="field1">
        	<div class="field2">
				<label for="web" class="label-field">Amount<b><font color="red" size="3">*</font></b></label>
		<input type="text" name="amount" id="amount" placeholder="Enter Amount" onkeypress="return isNumberKey(event)"/>
			<div id="amountErrorLable" style="text-align: right;"></div></div>
            
            <div class="field2">
				<label for="email" class="label-field1">Currency</label>
				<select name="currency" class="select" id="currency">
                	
                    <option>NPR</option>
                   
               </select>
			</div>
		</div>	
        
    
		
		<div class="web" id="field1">
				
	            <label for="email" class="label-field">Withdrawal Method</label> 
				<select id="w_mode" onchange="" style="margin-left:0;margin-right:5px;width:225px;border:1px solid #D6D8DA; height:30px; padding:5px; font-size:12px; color:#333333;" name="idproof">
	                        <option value="" selected="selected">--Select Withdrawal Mode--</option>
	                        <option value="Check">Check (sent to address on file)</option>
	                        <option value="Wire">Wire</option>           
	                   </select>
			</div>
	
		<div class="text" id="field1">
			<label for="email" class="label-field">Additional Comments </label>
			<textarea name="text" placeholder="Write something to us" id="comments"></textarea>
		</div>
		
		<div class="submit" id="field1" style="margin-left:185px;">
			<input type="button" value="Send" id="send" name="send" onclick="formvalidation();"/>
			<input type="button" value="Close" onclick="window.close()"/>
		</div>
	</form>

</body>

</html>
